package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
public class Invoice extends BaseObject {
	@OneToOne(optional = false, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "order_id", unique = true)
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("title", title).append("type", type)
				.append("content", content).append("invoiceDate", invoiceDate)
				.append("amount", amount).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Invoice))
			return false;
		Invoice castOther = (Invoice) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(title, castOther.title).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(title).toHashCode();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
    @Column(name="invoice_date")
	public String getInvoiceDate() {
		return invoiceDate;
	}

	public void setInvoiceDate(String invoiceDate) {
		this.invoiceDate = invoiceDate;
	}
	@Embedded
	public Amount getAmount() {
		return amount;
	}

	public void setAmount(Amount amount) {
		this.amount = amount;
	}

	private Long id;
	private String title;
	private String type;
	private String content;
	private String invoiceDate;
	private Amount amount=new Amount();
	private Order order;

}
